import { useNavigate } from 'react-router-dom'
import '../assets/css/CenterListItem.css'
import store from '../redux/store'
import { removeChat, saveMsgAvatar, saveName } from '../redux/action'
function CenterListItem(props) {
    const navigate = useNavigate()
    function dashenMsg() {
        return (
            <div>
                <p>职位: {props.data.job}</p>
                <p>公司: {props.data.companyName}</p>
                <p>要求: {props.data.jobRequirements}</p>
                <p>薪资: {props.data.positionSalary}</p>
            </div>
        )
    }
    function laobanMsg() {
        return (
            <div>
                <p>职位: {props.data.job}</p>
                <p>简介: {props.data.personalIntroduction}</p>
            </div>
        )
    }
    return (
        <div className='centerListItem' onClick={() => {
            store.dispatch(saveName(props.data.dashenName == undefined ? props.data.laobanName : props.data.dashenName))
            store.dispatch(removeChat())
            store.dispatch(saveMsgAvatar(props.data.avatar))
            navigate('/main/Chat', { state: { name: props.data.dashenName == undefined ? props.data.laobanName : props.data.dashenName } })
        }}>
            <div className="contaier">
                <img className='pic' src={props.data.avatar} width="20%" alt="" />
                <span className='name'>{props.data.dashenName == undefined ? props.data.laobanName : props.data.dashenName}</span>
                <hr />
                {props.flag ? dashenMsg() : laobanMsg()}
            </div>
        </div>
    )
}

export default CenterListItem